package com.ctgu.springboot.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.TraInfo;
import com.ctgu.springboot.mapper.TeamMapper;
import com.ctgu.springboot.mapper.TeamlogMapper;
import com.ctgu.springboot.entity.Teamlog;
import com.ctgu.springboot.mapper.TraInfoMapper;
import com.ctgu.springboot.service.TeamlogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@Service
public class TeamlogServiceImpl extends ServiceImpl<TeamlogMapper, Teamlog> implements TeamlogService {
    @Resource
    private TeamlogMapper teamlogMapper;

    @Override
    public IPage<Teamlog> teamlogPage(QueryPageParam query) {

        Integer id = (Integer) query.getParam().get("teamlog_id");
        String name = (String) query.getParam().get("teamlog_name");
        Integer teamId = (Integer) query.getParam().get("team_id");
        String teamlogDate = (String) query.getParam().get("teamlog_date");
        String teamlogContent = (String) query.getParam().get("teamlog_content");
        String teamContent = (String) query.getParam().get("team_content");
        String teamLogState = (String) query.getParam().get("team_log_state");

        Page<Teamlog> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Teamlog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(Teamlog::getTeamlogId, id);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(Teamlog::getTeamlogName, name);
        }
        if (teamId!=null) {
            lambdaQueryWrapper.like(Teamlog::getTeamId, teamId);
        }
        if (StringUtils.isNotBlank(teamlogDate) && !"null".equals(teamlogDate)) {
            lambdaQueryWrapper.eq(Teamlog::getTeamlogDate, teamlogDate);
        }
        if (StringUtils.isNotBlank(teamlogContent) && !"null".equals(teamlogContent)) {
            lambdaQueryWrapper.eq(Teamlog::getTeamlogContent, teamlogContent);
        }
        if (StringUtils.isNotBlank(teamContent) && !"null".equals(teamContent)) {
            lambdaQueryWrapper.eq(Teamlog::getTeamComment, teamlogContent);
        }
        if (StringUtils.isNotBlank(teamLogState) && !"null".equals(teamLogState)) {
            lambdaQueryWrapper.eq(Teamlog::getTeamLogState, teamLogState);
        }
        return teamlogMapper.teamlogPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<Teamlog> getList(){
        return teamlogMapper.getList();
    }
}
